package com.ymatou.startApp;

import java.io.IOException;
import java.util.HashSet;

import android.os.RemoteException;

import com.android.uiautomator.core.UiCollection;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.ymatou.util.Random;

@SuppressWarnings("deprecation")
public class PersonalInterestTest extends UiAutomatorTestCase{
	
	public static void personalInterest() throws IOException, 
		UiObjectNotFoundException, RemoteException {
        
        UiSelector likesWhich_s = new UiSelector().textStartsWith("哈尼喜欢哪些");
        UiSelector likesWhich_parent_s = likesWhich_s.fromParent(likesWhich_s);
        UiObject likesWhich_parent_o = new UiObject(likesWhich_parent_s);
        
        if (likesWhich_parent_o.exists()) {
        	//随机选择3个个人兴趣
        	UiCollection collection = new UiCollection(new UiSelector().resourceId("com.ymatou.shop:id/grid"));
        	HashSet<Integer> set = new HashSet<Integer>();
        	Random.randomSet(0, 10, 3, set);
        	
        	for (int j : set) {  
        		UiObject o = collection.getChildByInstance(new UiSelector().resourceId("com.ymatou.shop:id/img_productType"), j);
            	o.click();
        	}
        	
        	/*UiObject o1 = collection.getChildByInstance(new UiSelector().resourceId("com.ymatou.shop:id/rela_productTypeChecked"), 11);
        	o1.click();*/
        	//选择完个人兴趣后，点击确定
        	UiSelector bottom_button_s = new UiSelector().textStartsWith("开启海淘之旅");
            UiObject bottom_button_o = new UiObject(bottom_button_s);
        	bottom_button_o.click();
        }
    }
}
